package edu.cmu.fithub.formbeans;

import java.util.ArrayList;
import java.util.List;
import org.mybeans.form.FormBean;

public class AddWorkoutForm extends FormBean {

	private String username;
	private String email;
	private ArrayList<WorkoutEntry> entries;
	private String action;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public ArrayList<WorkoutEntry> getEntries() {
		return entries;
	}

	public void setEntries(ArrayList<WorkoutEntry> entries) {
		this.entries = entries;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (username == null || username.length() == 0) {
			errors.add("UserName is required");
		} else if (username.matches(".*[<>].*")) {
			errors.add("Username may not contain angle brackets");
			username = username.replaceAll(">", "&gt;");
			username = username.replaceAll("<", "&lt;");
			username = username.replaceAll(" ", "&nbsp;");
		}
		if (email == null || email.length() == 0) {
			errors.add("Email is required");
		} else if (username.matches(".*[<>].*")) {
			errors.add("Invalid Email");
		}

		if (username == null || username.length() == 0) {
			errors.add("UserName is required");
		}

		return errors;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}
}
